package com.ruoyi.waterDistribution.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.business.waterDistribution.WiPeriodY;
import com.ruoyi.waterDistribution.service.IWiPeriodYService;
import com.ruoyi.waterDistribution.vo.WiPeriodYVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 年度作物灌溉周期Controller
 *
 * @author ps
 * @date 2023-02-16
 */
@RestController
@RequestMapping("/WiPeriodY")
public class WiPeriodYController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(WiCropYController.class);

    @Autowired
    private IWiPeriodYService wiPeriodYService;

    /**
     * 查询年度作物灌溉周期列表
     */
    @RequiresPermissions("distribute:WiPeriodY:list")
    @GetMapping("/list")
    public TableDataInfo list(WiPeriodY wiPeriodY)
    {
        log.info("查询年度作物灌溉周期列表 ===== " + wiPeriodY);
        startPage();
        List<WiPeriodYVo> list = wiPeriodYService.selectWiPeriodYList(wiPeriodY);
        return getDataTable(list);
    }

    /**
     * 导出年度作物灌溉周期列表
     */
    @RequiresPermissions("distribute:WiPeriodY:export")
    @Log(title = "年度作物灌溉周期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WiPeriodYVo wiPeriodY)
    {
        List<WiPeriodYVo> list = wiPeriodYService.selectWiPeriodYList(wiPeriodY);
        ExcelUtil<WiPeriodYVo> util = new ExcelUtil<>(WiPeriodYVo.class);
        util.exportExcel(response, list, "年度作物灌溉周期数据");
    }

    /**
     * 获取年度作物灌溉周期详细信息
     */
    @RequiresPermissions("distribute:WiPeriodY:query")
    @GetMapping(value = "/{cropYr}/{plantCd}")
    public AjaxResult getInfo(@PathVariable("cropYr") String cropYr, @PathVariable("plantCd") String plantCd)
    {
        log.info("获取年度作物灌溉周期详细信息 ======= " + cropYr);
        WiPeriodY wiPeriodY = new WiPeriodY();
        wiPeriodY.setCropYr(cropYr);
        wiPeriodY.setPlantCd(plantCd);
        return success(wiPeriodYService.selectWiPeriodYByCropYr(wiPeriodY));
    }

    /**
     * 新增年度作物灌溉周期
     */
    @RequiresPermissions("distribute:WiPeriodY:add")
    @Log(title = "年度作物灌溉周期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WiPeriodYVo wiPeriodYVo)
    {
        log.info("新增年度作物灌溉周期 ======= " + wiPeriodYVo);
        return toAjax(wiPeriodYService.insertWiPeriodY(wiPeriodYVo));
    }

    /**
     * 修改年度作物灌溉周期
     */
    @RequiresPermissions("distribute:WiPeriodY:edit")
    @Log(title = "年度作物灌溉周期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WiPeriodYVo wiPeriodYVo)
    {
        log.info("修改年度作物灌溉周期 ===== " + wiPeriodYVo);
        return toAjax(wiPeriodYService.updateWiPeriodY(wiPeriodYVo));
    }

    /**
     * 删除年度作物灌溉周期
     */
    @RequiresPermissions("distribute:WiPeriodY:remove")
    @Log(title = "年度作物灌溉周期", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public AjaxResult remove(WiPeriodYVo wiPeriodYVo)
    {
        log.info("删除年度作物灌溉周期 ===== " + wiPeriodYVo);
        return toAjax(wiPeriodYService.deleteWiPeriodYByCropYr(wiPeriodYVo));
    }
}